
//获取应用实例
const app = getApp();
var commonData = require('../../data/data.js');
Page({
  data: {
    nickName: "",
    userImg: "",
    height:600,
    hardText:"",
    soure:0,
    catPrice:0
  },

  onLoad: function (option) {
    var that = this;
    var hard = "简单";
    console.log(option.hardtype)
    switch (option.hardtype){
      case '1':
        hard="简单";
        break;
      case '2':
        hard="困难";
        break;
      case '3':
        hard="噩梦";
        break;
    }
    this.setData({
      hardText:hard,
      soure: option.soure,
      catPrice: option.price
    })
    wx.getUserInfo({
      success: function (res) {
        that.setData({
          nickName: res.userInfo.nickName,
          userImg: res.userInfo.avatarUrl
        })
      }
    })
    this.getSystermMsg();
  },
  //获取屏幕高度，宽度
  getSystermMsg: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        commonData.screenInfo.height = res.windowHeight;
        that.setData({
          height: res.windowHeight
        })
      }
    })
  },
  onShow: function () {
    wx.showShareMenu({
      withShareTicket: true
    })
  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '快来参与保卫猫园守护战',
      path: '/pages/index/index',
      success: function (res) {
        //getSystemInfo是为了获取当前设备信息，判断是android还是ios，如果是android
        //还需要调用wx.getShareInfo()，只有当成功回调才是转发群，ios就只需判断shareTickets
        wx.getSystemInfo({
          success: function (d) {
            // console.log(d.platform);
            //console.log(res.shareTickets);
            if (res.shareTickets == null) {

              return;
            }
            if (d.platform == 'android' && (res.shareTickets.length > 0)) {
              wx.getShareInfo({
                shareTicket: res.shareTickets,
                success: function () {
                  //console.log("安卓群");
                  //app.sharePage();
                  wx.showToast({
                    title: "分享成功",
                    duration: 2000
                  });
                },
                fail: function () {
                  console(213123);
                  wx.showToast({
                    title: "分享成功",
                    duration: 2000
                  });
                }
              })
              return;
            }
            if (d.platform == 'ios' && (res.shareTickets.length > 0)) {

              //console.log("IOS群");
              //app.sharePage();
              wx.showToast({
                title: "分享成功",
                duration: 2000
              });
            } else {
              wx.showToast({
                title: "分享成功",
                duration: 2000
              });
            }
          },
          fail: function (res) {
            wx.showToast({
              title: "转发失败",
              duration: 2000
            });
          }
        })
      },
      fail: function (res) {
        // 转发失败
        console.log("取消转发");
      }
    }
  },
  gotoIndex:function(){
      wx.switchTab({
        url: '/pages/index/index',
      })
  }
})
